package com.wiwf.model.manage.listener;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.JavaDelegate;

public class AdditionListener implements JavaDelegate {
	
	private static final long serialVersionUID = 1L;

	@Override
	public void execute(DelegateExecution execution) {
		Double numA = getNumberA(execution);
        Double numB = getNumberB(execution);
        Double result = numA + numB;
        System.out.println("加法结果: " + result);

        // 设置流程变量
        execution.setVariable("result", result);
	}

    private Expression numberA;
    private Expression numberB;

    public Double getNumberA(DelegateExecution execution) {
    	Object value = numberA.getValue(execution);
        if (value instanceof String) {
            return Double.parseDouble(value.toString());
        } else if (value instanceof Integer) {
            return Double.parseDouble(value.toString());
        }
    	return (Double) value;
    }

    public void setNumberA(Expression numberA) {
        this.numberA = numberA;
    }

    public Double getNumberB(DelegateExecution execution) {
    	Object value = numberB.getValue(execution);
        if (value instanceof String) {
            return Double.parseDouble(value.toString());
        } else if (value instanceof Integer) {
            return Double.parseDouble(value.toString());
        }
    	return (Double) value;
    }

    public void setNumberB(Expression numberB) {
        this.numberB = numberB;
    }

}